load c:\manoj\projects\ace\kak_h;
load c:\manoj\projects\ace\substorm;
%load c:\manoj\projects\ace\rand_substorm.mat
load c:\manoj\projects\substorm\selected_substorm selected_substorm;
fday_substorm = selected_substorm;

%night
st = 14/24;
en = 20/24;
%day
% st = 0;
% en = 7;
i_counter=0;
radius_epoch = 1/24;
kak_mean = nanmean(KAK_H_DAILY);
for i = 1:length(fday_substorm),
    
    
    if fday_substorm(i)-floor(fday_substorm(i)) > st & ...
            fday_substorm(i)-floor(fday_substorm(i)) < en,
        
       [fday_int,ii] = intersect(fday_kak,floor(fday_substorm(i)));
       if ~isempty(fday_int),
          fday_frac = fday_kak(ii)+magnetic_frac;
           if fday_frac(1) < fday_substorm(i)-radius_epoch & ...
               fday_frac(end) > fday_substorm(i)+radius_epoch,
                     i_counter = i_counter+1;
           
           L = fday_frac > fday_substorm(i)-radius_epoch & ...
               fday_frac < fday_substorm(i)+radius_epoch;
           
           if sum(L) > floor(radius_epoch*2*1440),
               kkk = find(L ==1);
               L(kkk(1)) = 0;
           end;
           
           dummy = KAK_H_DAILY(ii,:)- kak_mean;
           SEG_HUA(i_counter,:) = dummy(L);
           end;
           
           end;
       end;
    end;

plot((-radius_epoch*1440) + 0.5 : 1 :  (radius_epoch*1440) - 0.5 ,nanmean(SEG_HUA),'r');